//
//  HWLogCell.m
//  MINISOEA
//
//  Created by 李含文 on 2021/4/28.
//  Copyright © 2021 MINISO. All rights reserved.
//

#import "HWLogCell.h"
#import "HWRequestLogManage.h"

@interface HWLogCell()
@property (weak, nonatomic) IBOutlet UILabel *label_1;
@property (weak, nonatomic) IBOutlet UILabel *label_2;
@property (weak, nonatomic) IBOutlet UILabel *label_3;

@property (weak, nonatomic) IBOutlet UILabel *label_4;
@property (weak, nonatomic) IBOutlet UILabel *label_5;

@property (weak, nonatomic) IBOutlet UILabel *label_6;

@end

@implementation HWLogCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.label_6.hidden = YES;
    self.label_4.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *gest = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
    gest.minimumPressDuration = 1;
    [_label_4 addGestureRecognizer:gest];
}

- (void)handleLongPress:(UILongPressGestureRecognizer *)gest {
    UILabel *label = (UILabel *)gest.view;
    [[UIPasteboard generalPasteboard] setString:label.text];
    self.label_6.hidden = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        self.label_6.hidden = YES;
    });
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(HWLogModel *)model {
    _model = model;
    self.label_1.text = [NSString stringWithFormat:@"[%@] %@", model.HTTPMethod, model.url];
    self.label_2.text = model.timeString;
    self.label_4.text = model.vcName;
    self.label_5.text = model.vctitle;
    if (model.code == -1) {
        self.label_3.text = @"异常";
        self.label_3.backgroundColor = UIColor.redColor;
    } else if (model.code == success_Code) {
        self.label_3.text = @"成功";
        self.label_3.backgroundColor = UIColor.greenColor;
    } else if (model.code == 0) {
        self.label_3.text = @"";
        self.label_3.backgroundColor = UIColor.whiteColor;
    } else {
        self.label_3.text = @"失败";
        self.label_3.backgroundColor = UIColor.yellowColor;
    }
}

@end
